package com.hzw.saas.service.app.client.service;

import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzw.saas.api.client.IClientAppService;
import com.hzw.saas.api.client.bo.ClientAppBo;
import com.hzw.saas.api.client.query.ClientAppQuery;
import com.hzw.saas.common.config.util.AssertUtil;
import com.hzw.saas.common.util.MapperUtil;
import com.hzw.saas.common.util.ObjFieldUtil;
import com.hzw.saas.service.app.client.mapper.ClientAppMapper;
import com.hzw.saas.service.app.client.model.ClientApp;
import org.springframework.stereotype.Service;

/**
 * @author hankun
 */
@Service
public class ClientAppServiceImpl extends ServiceImpl<ClientAppMapper, ClientApp> implements IClientAppService, IService<ClientApp> {
    @Override
    public ClientAppBo getLatestVersion(ClientAppQuery clientAppQuery) {
        AssertUtil.assertThrow("缺少相应参数", ObjFieldUtil.hasBlankFiled(clientAppQuery));

        ClientApp clientApp = this.lambdaQuery().eq(ClientApp::getAppId, clientAppQuery.getAppId())
            .eq(ClientApp::getAppEnv, clientAppQuery.getAppEnv())
            .orderByDesc(ClientApp::getPubDate)
            .last("limit 1")
            .one();
        return MapperUtil.nf().map(clientApp, ClientAppBo.class);
    }
}
